package chapter06

/**
 * TODO 1、特质的叠加
 * TODO 2、钻石问题特征叠加
 * TODO 3、特质和抽象类的区别
 * 对于当前的特征和抽象类、想要给他参数的时候还是优先使用抽象类
 */
object Test15_TraitOverlying {

  def main(args: Array[String]): Unit = {
    val student1 = new Student15
    student1.increase()


    //TODO 2、钻石问题特征叠加
    val ball = new MyFootBall
    println(ball.describe())
  }


}

//特质1
trait Knowledge15 {
  var amount: Int = 0;

  def increase(): Unit = {
    println("Knowledge increased")

  }
}

//特质2
trait Talent15 {
  def singing: Unit

  def dancing: Unit

  def increase(): Unit = {
    println("Talent increased")

  }
}

/**
 * 实现两个特质
 */
class Student15 extends Person13 with Talent15 with Knowledge15 {
  override def dancing: Unit = println("dancing")

  override def singing: Unit = println("singing")

  //TODO 1、 调用的是最后的特征 Knowledge15 里面的方法
  //TODO 2、 解决冲突的特征、跟父类是没有关系的
  override def increase(): Unit = {
    super.increase();
  }
}


//Td 钻石问题二
//定义球类特质0
trait Ball {
  def describe(): String = "ball"
}

//定义颜色特质1
trait ColorBall extends Ball {
  var color: String = "red"

  override def describe(): String = color + "_" + super.describe()
}

//定义种类的特征2
trait CategoryBall extends Ball {
  def category: String = "foot"

  override def describe(): String = category + "_" + super.describe()
}


//定义一个自定义的球类3
//TODO 从右到左开始
class MyFootBall extends CategoryBall with ColorBall {
  override def describe(): String = "my ball is a " + super.describe()
}